package com.ruoyi.project.web.safeRule.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.web.safeRule.domain.SafeRule;
import com.ruoyi.project.web.safeRule.service.ISafeRuleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 安全细则Controller
 * 
 * @author ruoyi
 * @date 2021-01-28
 */
@Controller
@RequestMapping("/web/safeRule")
public class SafeRuleController extends BaseController
{
    private String prefix = "web/safeRule";

    @Autowired
    private ISafeRuleService safeRuleService;

    @RequiresPermissions("web:safeRule:view")
    @GetMapping()
    public String safeRule()
    {
        return prefix + "/safeRule";
    }

    /**
     * 查询安全细则列表
     */
    @RequiresPermissions("web:safeRule:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SafeRule safeRule)
    {
        startPage();
        List<SafeRule> list = safeRuleService.selectSafeRuleList(safeRule);
        return getDataTable(list);
    }

    /**
     * 导出安全细则列表
     */
    @RequiresPermissions("web:safeRule:export")
    @Log(title = "安全细则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SafeRule safeRule)
    {
        List<SafeRule> list = safeRuleService.selectSafeRuleList(safeRule);
        ExcelUtil<SafeRule> util = new ExcelUtil<SafeRule>(SafeRule.class);
        return util.exportExcel(list, "safeRule");
    }

    /**
     * 新增安全细则
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存安全细则
     */
    @RequiresPermissions("web:safeRule:add")
    @Log(title = "安全细则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SafeRule safeRule)
    {
        return toAjax(safeRuleService.insertSafeRule(safeRule));
    }

    /**
     * 修改安全细则
     */
    @GetMapping("/edit/{ruleId}")
    public String edit(@PathVariable("ruleId") Long ruleId, ModelMap mmap)
    {
        SafeRule safeRule = safeRuleService.selectSafeRuleById(ruleId);
        mmap.put("safeRule", safeRule);
        return prefix + "/edit";
    }

    /**
     * 修改保存安全细则
     */
    @RequiresPermissions("web:safeRule:edit")
    @Log(title = "安全细则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SafeRule safeRule)
    {
        return toAjax(safeRuleService.updateSafeRule(safeRule));
    }

    /**
     * 删除安全细则
     */
    @RequiresPermissions("web:safeRule:remove")
    @Log(title = "安全细则", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(safeRuleService.deleteSafeRuleByIds(ids));
    }
}
